/**
 * Created by 王健 on 2019-12-10.
 */
$(function () {

    var html_data = {
        baseConfig: baseConfig,
        sessionid: '',
        sessionid_q: '',
        userinfo:{tel:""},
        default_address: null,
        selected_address_id: parseInt(GetQueryString('address_id')),
        payorder_id: parseInt(GetQueryString("payorder_id")),
        address_list: []

    };
    var app = new Vue({
        el: '#user_info',
        data: html_data,
        methods: {

            send_phone_code:function(){
               if(!html_data.userinfo.imgcode||html_data.userinfo.imgcode.length!=4){
                   Magiclamp.mcAlert("提示", "请填写图片验证码", "好", function () {

                   });
               }else if(!html_data.userinfo.tel||html_data.userinfo.tel.length!=11){
                   Magiclamp.mcAlert("提示", "请输入正确的手机号", "好", function () {

                   });
               }else{
                   api.sys.get_pass_sms_code({code:html_data.userinfo.imgcode, tel:html_data.userinfo.tel}).then(function (value) {
                       Magiclamp.mcAlert("提示", value.message, "好", function () {

                       });
                   })
               }
            },
            save_alipay:function(){
                if(!html_data.userinfo.password||html_data.userinfo.password.length<6||html_data.userinfo.password.length>17){
                    Magiclamp.mcAlert("提示", "请输入6~16位字母、数字组成的密码", "好", function () {

                    });
                }else{
                    api.sys.set_tel_and_pwd_sms_code({code:html_data.userinfo.code, tel:html_data.userinfo.tel, pwd:html_data.userinfo.password}).then(function (value) {
                        Magiclamp.mcAlert("提示", value.message, "好", function () {

                        });
                    })
                }

            },
            refresh_img_code:function(){
                var img = document.getElementById("image_code");
                html_data.userinfo.t = new Date().getTime();
                img.src =baseConfig.host+'/sys/image_code?t='+html_data.userinfo.t+"&sessionid="+html_data.sessionid;
            },
            page_back: function () {
                baseConfig.page_back();
            }
        }
    });

    html_data.sessionid = GetQueryString('sessionid');
    if (html_data.sessionid) {
        html_data.sessionid_q = "sessionid=" + html_data.sessionid;
        client_storage('sessionid', html_data.sessionid);
    }

    var img = document.getElementById("image_code");
    img.src =baseConfig.host+'/sys/image_code?sessionid='+html_data.sessionid;

    setTimeout(function () {
        api.sys.my_userinfo().then(function (value) {
            if(value.result.username.length==11){
                html_data.userinfo.tel = value.result.username;
            }else{
                Magiclamp.mcAlert("提示", "请先设置手机号", "好", function () {

                });
            }

        })
    }, 1000);


});
